package org.zhadoop.stream.cql.semanticanalyzer.parser.context;

import org.zhadoop.stream.cql.exception.SemanticAnalyzerException;
import org.zhadoop.stream.cql.semanticanalyzer.CreateOutputStreamAnalyzer;
import org.zhadoop.stream.cql.semanticanalyzer.SemanticAnalyzer;
import org.zhadoop.stream.cql.semanticanalyzer.parsecontextwalker.ParseContextWalker;

/**
 * 创建输出流语法解析内容
 * 
 * @author zwd
 *
 */
public class CreateOutputStatementContext extends CreateStreamStatementContext {

	private ClassNameContext serClassName;

	private StreamPropertiesContext serProperties;

	private ClassNameContext sinkClassName;

	private StreamPropertiesContext sinkProperties;

	private ParallelClauseContext parallelNumber;

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();

		sb.append("CREATE OUTPUT STREAM ");
		sb.append(getStreamName());
		sb.append(" " + getColumns().toString());

		if (serClassName != null) {
			sb.append(" SERDE " + serClassName.toString());
		}

		if (serProperties != null) {
			sb.append(" " + serProperties.toString());
		}

		sb.append(" SINK " + sinkClassName.toString());
		if (sinkProperties != null) {
			sb.append(" " + sinkProperties.toString());
		}

		if (parallelNumber != null) {
			sb.append(" " + parallelNumber.toString());
		}

		return sb.toString();
	}
	
	@Override
	public SemanticAnalyzer createAnalyzer() throws SemanticAnalyzerException {
		return new CreateOutputStreamAnalyzer(this);
	}

	public ClassNameContext getSerClassName() {
		return serClassName;
	}

	public void setSerClassName(ClassNameContext serClassName) {
		this.serClassName = serClassName;
	}

	public StreamPropertiesContext getSerProperties() {
		return serProperties;
	}

	public void setSerProperties(StreamPropertiesContext serProperties) {
		this.serProperties = serProperties;
	}

	public ClassNameContext getSinkClassName() {
		return sinkClassName;
	}

	public void setSinkClassName(ClassNameContext sinkClassName) {
		this.sinkClassName = sinkClassName;
	}

	public StreamPropertiesContext getSinkProperties() {
		return sinkProperties;
	}

	public void setSinkProperties(StreamPropertiesContext sinkProperties) {
		this.sinkProperties = sinkProperties;
	}

	public ParallelClauseContext getParallelNumber() {
		return parallelNumber;
	}

	public void setParallelNumber(ParallelClauseContext parallelNumber) {
		this.parallelNumber = parallelNumber;
	}
	
	@Override
	protected void walkChild(ParseContextWalker walker) {
		super.walkChild(walker);
		walkExpression(walker, parallelNumber);
		walkExpression(walker, serProperties);
		walkExpression(walker, sinkProperties);
	}
}
